package com.youtitleit.dao;

import java.util.List;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;

import com.youtitleit.model.Caption;


public class CaptionDao {
	
private PersistenceManagerFactory persistenceManagerFactory;
	
	private static CaptionDao instance = null;
	
	public static CaptionDao getInstance() {
		
		if(instance == null) {
			instance = new CaptionDao();
		}
		
		return instance;
	}

	private CaptionDao() {
		persistenceManagerFactory = JDOHelper.getPersistenceManagerFactory("transactions-optional");
	}
	
	public Caption save(Caption caption) {
		
		PersistenceManager persistenceManager = persistenceManagerFactory.getPersistenceManager();
		
		try {
			caption = persistenceManager.makePersistent(caption);
		}finally {
			persistenceManager.close();
		}
		
		return caption;
		
	}
}
